Interface yii\db\ActiveQueryInterface

Extendsyii\db\QueryInterface
Implemented byspinitron\dynamicAr\DynamicActiveQuery, tests\unit\data\CustomerQuery, yii\db\ActiveQuery
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/db/ActiveQueryInterface.php

ActiveQueryInterface defines the common interface to be implemented by active record query classes.

That are methods for either normal queries that return active records but also relational queries in which the query represents a relation between two active record classes and will return related records only.

A class implementing this interface should also use yii\db\ActiveQueryTrait and yii\db\ActiveRelationTrait.

Public Methods

Hide inherited methods

MethodDescriptionDefined By
addOrderBy() Adds additional ORDER BY columns to the query. yii\db\QueryInterface
all() Executes the query and returns all results as an array. yii\db\QueryInterface
andFilterWhere() Adds an additional WHERE condition to the existing one ignoring empty parameters. yii\db\QueryInterface
andWhere() Adds an additional WHERE condition to the existing one. yii\db\QueryInterface
asArray() Sets the asArray() property. yii\db\ActiveQueryInterface
count() Returns the number of records. yii\db\QueryInterface
exists() Returns a value indicating whether the query result contains any row of data. yii\db\QueryInterface
filterWhere() Sets the WHERE part of the query ignoring empty parameters. yii\db\QueryInterface
findFor() Finds the related records for the specified primary record. yii\db\ActiveQueryInterface
indexBy() Sets the indexBy() property. yii\db\ActiveQueryInterface
limit() Sets the LIMIT part of the query. yii\db\QueryInterface
offset() Sets the OFFSET part of the query. yii\db\QueryInterface
one() Executes the query and returns a single row of result. yii\db\QueryInterface
orFilterWhere() Adds an additional WHERE condition to the existing one ignoring empty parameters. yii\db\QueryInterface
orWhere() Adds an additional WHERE condition to the existing one. yii\db\QueryInterface
orderBy() Sets the ORDER BY part of the query. yii\db\QueryInterface
via() Specifies the relation associated with the junction table for use in relational query. yii\db\ActiveQueryInterface
where() Sets the WHERE part of the query. yii\db\QueryInterface
with() Specifies the relations with which this query should be performed. yii\db\ActiveQueryInterface

Method Details

asArray() public abstract method

Sets the asArray() property.

public abstract static asArray ( $value true )
$value boolean

Whether to return the query results in terms of arrays instead of Active Records.

return static

The query object itself

findFor() public abstract method

Finds the related records for the specified primary record.

This method is invoked when a relation of an ActiveRecord is being accessed in a lazy fashion.

public abstract mixed findFor ( $name, $model )
$name string

The relation name

$model yii\db\ActiveRecordInterface

The primary model

return mixed

The related record(s)

indexBy() public abstract method

Sets the indexBy() property.

public abstract static indexBy ( $column )
$column string|callable

The name of the column by which the query results should be indexed by. This can also be a callable (e.g. anonymous function) that returns the index value based on the given row or model data. The signature of the callable should be:

// $model is an AR instance when `asArray` is false,
// or an array of column values when `asArray` is true.
function ($model)
{
    // return the index value corresponding to $model
}
return static

The query object itself

via() public abstract method

Specifies the relation associated with the junction table for use in relational query.

public abstract static via ( $relationName, callable $callable null )
$relationName string

The relation name. This refers to a relation declared in the primaryModel of the relation.

$callable callable

A PHP callback for customizing the relation associated with the junction table. Its signature should be function($query), where $query is the query to be customized.

return static

The relation object itself.

with() public abstract method

Specifies the relations with which this query should be performed.

The parameters to this method can be either one or multiple strings, or a single array of relation names and the optional callbacks to customize the relations.

A relation name can refer to a relation defined in modelClass or a sub-relation that stands for a relation of a related record. For example, orders.address means the address relation defined in the model class corresponding to the orders relation.

The following are some usage examples:

// find customers together with their orders and country
Customer::find()->with('orders', 'country')->all();
// find customers together with their orders and the orders' shipping address
Customer::find()->with('orders.address')->all();
// find customers together with their country and orders of status 1
Customer::find()->with([
    'orders' => function ($query) {
        $query->andWhere('status = 1');
    },
    'country',
])->all();
public abstract static with ( )
return static

The query object itself